package zx.x.modules.yshbms.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.R;
import zx.x.modules.yshapp.entity.CommunityEntity;
import zx.x.modules.yshbms.service.CommunityService;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 *
 * @author x
 * @email x
 */
@RestController
@RequestMapping("yshbms/community")
public class CommunityController {
    @Autowired
    private CommunityService communityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = communityService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(CommunityEntity communityEntity){
        communityEntity.setCjTime(new Date());
        communityEntity.setDeleteFlag(0);
        communityService.save(communityEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(CommunityEntity communityEntity){
        communityEntity.setUpdateTime(new Date());
        communityService.updateById(communityEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        CommunityEntity community = communityService.getById(id);
        return R.ok().put("community", community);
    }


}
